<?php
namespace Console\Controller;
use Think\Controller;

class TransferController extends Controller {
	
    public function index()
	{       
		$patientObj = M("patient");
		$map = array(
				'car_close' => 1,
				'hospital_close' => 1,
				'keshi_id' => $_SESSION['doctor_data']['keshi_id'],
				'hospital_id' => $_SESSION['doctor_data']['hospital_id'],
			);
		$patient = $patientObj->where($map)->order('create_time DESC')->select();
		
		$this->assign('patient', $patient);
		$this->display();
    }
	
	public function printPage()
	{
		$congfigObj = M('config');
		
		$id = I('get.id');
		$patientObj = M("patient");
		$patient = $patientObj->find($id);
		//获取送达医院
		$hospitalObj = M('hospital');
		$hospitalData = $hospitalObj->where('id ='.$patient['hospital_id'])->find();
		$hospital = $hospitalData['name'];
		
		//获取病情判断
		$juggmentData = $congfigObj->where('id = '.$patient['juggment'])->find();
		$juggment = $juggmentData['name'];
		
		//获取意识
		$mindData = $congfigObj->where('id = '.$patient['mind'])->find();
		$mind = $mindData['name'];
		
		//获取皮肤
		$skinData = $congfigObj->where('id = '.$patient['skin'])->find();
		$skin = $skinData['name'];
		
		//获取瞳孔
		$sightData = $congfigObj->where('id = '.$patient['sight'])->find();
		$sight = $sightData['name'];
		
		//获取对光反射
		$lightData = $congfigObj->where('id = '.$patient['light'])->find();
		$light = $lightData['name'];
		
		//获取辅助检查
		//首次
		$lifeObj = M('patient_life_status');
		$checkFirst =  $lifeObj->order('record_time ASC')->where("patient_id =".$id)->find();
		$checkLast  =  $lifeObj->order('record_time DESC')->where("patient_id =".$id)->find();
		
		//获取一般治疗
		$nomalCureObj = M('patient_normal_cure');
		$cure = $nomalCureObj->join("left join config on patient_normal_cure.method_id = config.id")
							->field("config.name")
							->where("patient_normal_cure.patient_id =".$id)->select();
		
		// 获取药物治疗
		$medicineCureObj = M('patient_medicine_cure');
		$medicine = $medicineCureObj					
							->join("left join aid_medicine on patient_medicine_cure.medicine_id = aid_medicine.id")
							->join("left join config on aid_medicine.method = config.id")
							->field("patient_medicine_cure.format as pformat, patient_medicine_cure.unit as punit, patient_medicine_cure.num as pnum, patient_medicine_cure.amount as pamount, aid_medicine.name as medicine_name, aid_medicine.format, aid_medicine.unit, aid_medicine.num, aid_medicine.amount, config.name as method_name")
							->where("patient_medicine_cure.patient_id =".$id)->select();
		
		$this->assign('patient', $patient);
		$this->assign('hospital', $hospital);
		$this->assign('juggment', $juggment);
		$this->assign('mind', $mind);
		$this->assign('skin', $skin);
		$this->assign('sight', $sight);
		$this->assign('light', $light);
		$this->assign('checkFirst', $checkFirst);
		$this->assign('checkLast', $checkLast);
		$this->assign('cure', $cure);
		$this->assign('medicine', $medicine);
		$this->display();
	}
}